package com.xiaopeng.system.test.model;

import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
public class Order {
    private Long orderId;       // 订单id
    private Long userId;        // 用户id
    private BigDecimal money;   // 金额


    public static void main(String[] args) {
        List<Order> list = new ArrayList<>();

        Map<Long, List<Long>> userOrderIdsMap = list.stream().collect(Collectors.groupingBy(Order::getUserId
                , Collectors.mapping(Order::getOrderId, Collectors.toList())));



        Map<Boolean, List<Order>> map = list.stream().collect(
                Collectors.partitioningBy(e -> e.getMoney().compareTo(new BigDecimal(100)) > 0));
        List<Order> matchList = map.get(true);      // 无数据时为空数组
        List<Order> notMatchList = map.get(false);  // 无数据时为空数组


        list = list.stream().sorted(
                Comparator.comparing(Order::getUserId, Comparator.reverseOrder())
                        .thenComparing(Order::getOrderId, Comparator.naturalOrder()))
                .collect(Collectors.toList());
    }
}
